package com.example.aixiangshou.runninggame;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.support.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.x_memteor.base_master.application.MyApplication;
import com.x_memteor.base_master.bean.ScorBean;
import com.x_memteor.base_master.view.SignSeekBar;

import java.util.List;

/**
 * @author: X_Meteor
 * @description: 类描述
 * @version: V_1.0.0
 * @date: 2018/5/24 16:03
 * @company:
 * @email: lx802315@163.com
 */
public class ShowScoreAdapter extends BaseQuickAdapter<ScorBean,BaseViewHolder> {

    public ShowScoreAdapter(int layoutResId, @Nullable List<ScorBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(final BaseViewHolder helper, ScorBean item) {

        final SignSeekBar signSeekBar = helper.getView(R.id.sign_seek_bar);

        signSeekBar.setmMax(MyApplication.getInstance().getGameBean().getGameDuration());
        signSeekBar.setmSectionCount(MyApplication.getInstance().getGameBean().getGameDuration());
        signSeekBar.setImvRes(item.getIcon());

        ValueAnimator animator = ValueAnimator.ofFloat(0, item.getTime());
        animator.setDuration(3000);
        animator.setStartDelay(helper.getPosition() * 3000);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                signSeekBar.setProgress((Float) animation.getAnimatedValue());
            }
        });

        animator.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (helper.getPosition() == mData.size() - 1){
                    mContext.startActivity(new Intent(mContext,WinActivity.class));
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator.start();
    }
}
